#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by Gu Xi on 2018/12/12
import pymongo


class MongoHelper:
    def __init__(self, mongodb_url, mongodb_name):
        self.client = pymongo.MongoClient(mongodb_url, connect=False)
        self.db = self.client[mongodb_name]

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.client.close()

    def close(self):
        self.client.close()
